﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_ProcecureMainController : BaseApiController
    {
        #region DI

        public PB_ProcecureMainController(IPB_ProcecureMainBusiness pB_ProcecureMainBus)
        {
            _pB_ProcecureMainBus = pB_ProcecureMainBus;
        }

        IPB_ProcecureMainBusiness _pB_ProcecureMainBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public string test(string DeptId)
        {
            return DeptId;
        }

        [HttpPost]
        public async Task<PageResult<PB_ProcecureMain>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_ProcecureMainBus.GetDataListAsync(input);
        }
        [HttpPost]
        public async Task<PageResult<PB_ProcecureMainDto>> GetDataLists(PageInput<ConditionDTO> input)
        {
            return await _pB_ProcecureMainBus.GetDataListAsyncs(input);
        }

        [HttpPost]
        public async Task<PageResult<PB_ProcecureMain>> GetDataListByDepartment(string DeptId)
        {
            return await _pB_ProcecureMainBus.GetDataListByDepartment(DeptId);
        }

        [HttpPost]
        public async Task<PB_ProcecureMain> GetTheData(IdInputDTO input)
        {
            return await _pB_ProcecureMainBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_ProcecureMain data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_ProcecureMainBus.AddDataAsync(data);
            }
            else
            {
                await _pB_ProcecureMainBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_ProcecureMainBus.DeleteDataAsync(ids);
        }

        [HttpPost]
        public async Task SaveListData(PB_ProcecureMainListDTO data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_ProcecureMainBus.AddData(data);
            }
            else
            {
                await _pB_ProcecureMainBus.UpdateData(data);
            }
        }

# region 通过主工序id查询前子工序所在的主工序列表
        /// <summary>
        /// 通过主工序id查询前子工序所在的主工序列表
        /// </summary>
        /// <param name="ParentId">工序id</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_ProcecureMainList> GetDataProceureMainByid(string ParentId)
        {
            var res = await _pB_ProcecureMainBus.GetDataProceureMain(ParentId);
            return res;
        }
        #endregion
        #endregion
    }
}